from typing import *


class Solution:

    def applyOperations(self, nums: List[int]) -> List[int]:
        i = z = 0
        n = len(nums)
        while i < n:
            if i < n - 1 and nums[i] == nums[i + 1]:
                nums[z] = nums[i] << 1
                i += 2
            else:
                nums[z] = nums[i]
                i += 1
            if nums[z] != 0:
                z += 1
        while z < n:
            nums[z] = 0
            z += 1
        return nums
